/**
 * @author lk
 * @date 2022/6/6 12:47
 */
package com.mmall.thread;

import java.util.concurrent.locks.ReentrantLock;

public class LockTest01 {
    private int i = 0;

    public static void main(String[] args) {
        LockTest01 lockTest01 = new LockTest01();
        lockTest01.extracted();
    }

    private void extracted() {
        ReentrantLock lock = new ReentrantLock();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> this.work(lock));
            thread.start();
        }
    }

    void work(ReentrantLock lock) {

        while (true) {
            lock.lock();
            i += 1;
            System.out.println(Thread.currentThread().getName() + ":" + i);
            lock.unlock();
        }
    }
}
